import type { SysConfig } from "@/pages/system/config/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
	//参数名称
	configName?: string;
	//参数键名
	configKey?: string;
	//参数类型
	configType?: string;
	//当前页码
	page: number;
	//每页数量
	pageSize: number;
}

export interface PageListRes {
	//总记录数
	total: number;
	//数据列表
	records: SysConfig[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
	apiClient.post({
		url: "/system/config/pageList",
		data,
	});

const getInfo = (id: React.Key): Promise<SysConfig> =>
	apiClient.get({
		url: `/system/config/${id}`,
	});

const add = (data: SysConfig): Promise<SysConfig> =>
	apiClient.post({
		url: "/system/config",
		data,
	});

const update = (data: SysConfig): Promise<SysConfig> =>
	apiClient.put({
		url: "/system/config",
		data,
	});

const remove = (ids: React.Key[]): Promise<void> =>
	apiClient.delete({
		url: "/system/config",
		params: {
			ids: ids.join(","),
		},
	});

export const sysConfigService = {
	pageList,
	getInfo,
	add,
	update,
	remove,
};

export default sysConfigService;
